package com.yangcheng.service.impl;

import com.yangcheng.dao.UserMapper;
import com.yangcheng.model.domain.User;
import com.yangcheng.service.IUserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
@Service("CustomerService")
public class UserServiceImpl  implements IUserService {
    @Resource
    private UserMapper userMapper;
    @Autowired
    RedisTemplate redisTemplate;


    @Override
    public User getCustomer(String username) {
        Object o = redisTemplate.opsForValue().get("customer_" + username);
        if (o != null) {
            return (User) o;
        }
        User customer = userMapper.getCustomer(username);
        if (null != customer) {
            redisTemplate.opsForValue().set("customer_" + username, customer);
        }
        return customer;
    }
}
